var MOD_COP={
  _opdate:new Date(),
  opdate:"",
  optime:"10.00",
  chairman:"CHAIRMAN",
  oprep:"REPRESENTATIVE",
  opid:"",
  opapp:"EPXXXXXXX"
};

MOD_COP._opdate.setDate(MOD_COP._opdate.getDate()+120);
MOD_COP.opdate=Date2str(MOD_COP._opdate);


MOD_COP.onscheduleop=function() {
  var ops= FindOPActions(GetDossierNumber());
  var id=0;
  if(!ops) {
    id=AddAction(GetDossierNumber(), GetClaimSetAppNum(),GetClaimSetVersion(),"OP",0,0,MOD_COP.opdate,"","","");
  } else {
    var act_iter=new actions_iterator(ops);
    while(!act_iter.end()) {
      id=act_iter.getID();
      act_iter.next();
    }
    if(get_action_attr(id,"ddate")){ // more than one OP ???
      EditAction(id,GetDossierNumber(),GetClaimSetAppNum(),GetClaimSetVersion(),"OP",0,0,MOD_COP.opdate,"","","");
    } else {
      id=AddAction(GetDossierNumber(), GetClaimSetAppNum(),GetClaimSetVersion(),"OP",0,0,MOD_COP.opdate,"","","");
    } 
  }
  set_action_attr(id,"ltime",MOD_COP.optime);
}

MOD_COP.recoverop=function() {
  var ops= FindOPActions(GetDossierNumber());
  var id;
  if(ops) {
    var act_iter=new actions_iterator(ops);
    while(!act_iter.end()) {
      id=act_iter.getID();
      act_iter.next();
    }
    MOD_COP.opdate=get_action_attr(id,"ldate") || Date2str(MOD_COP._opdate);
    MOD_COP.optime=get_action_attr(id,"ltime") || "10:00";
    MOD_COP.opapp =get_action_attr(id,"an")    || GetClaimSetAppNum();
  }
}

MOD_COP.updateop=function() {
  var ops= FindOPActions(GetDossierNumber());
  var id;
  if(ops) {
    var act_iter=new actions_iterator(ops);
    while(!act_iter.end()) {
      id=act_iter.getID();
      act_iter.next();
    }
    set_action_attr(id,"ldate",MOD_COP.opdate);
    set_action_attr(id,"ltime",MOD_COP.optime);
    SaveActions();
  }
}

MOD_COP.runningop=function() {
  var ops= FindOPActions(GetDossierNumber());
  var id;
  if(ops) {
    var act_iter=new actions_iterator(ops);
    while(!act_iter.end()) {
      id=act_iter.getID();
      act_iter.next();
    }
    // OP is scheduled
    if(!get_action_attr(id,"ddate")){
      return true;
    }
  }
  return false;
}
    

MOD_COP.onchangepdate=function(pdate) { 
  MOD_COP.opdate=pdate;
  MOD_COP.updateop();
  comm_area_update(MOD_COP.opid,do_prop(MOD_COP.opdate,MOD_COP.optime));
}

MOD_COP.onchangeptime=function(ptime) {
  MOD_COP.optime=ptime;
  MOD_COP.updateop(); 
  comm_area_update(MOD_COP.opid,do_prop(MOD_COP.opdate,MOD_COP.optime));
}

MOD_COP.onchangemchair=function(name) {
  MOD_COP.chairman=name;
  MOD_COP.updateop(); 
  comm_area_update(MOD_COP.opid,do_minutes(MOD_COP.chairman,MOD_COP.oprep,MOD_COP.optime));
}

MOD_COP.onchangemtime=function(mtime) {
  MOD_COP.optime=mtime; 
  comm_area_update(MOD_COP.opid,do_minutes(MOD_COP.chairman,MOD_COP.oprep,MOD_COP.optime));
}

MOD_COP.onchangemrep=function(mrep) {
  oprep=mrep; 

  comm_area_update(MOD_COP.opid,do_minutes(MOD_COP.chairman,MOD_COP.oprep,MOD_COP.optime));
}

MOD_COP.onchangeopapp=function(opa) {
  MOD_COP.opapp=opa; 
  comm_area_update(MOD_COP.opid,do_minutes());
}

// EPC2K OK
function do_prop() {
var allcl =GetAllClaims("U");
var allnov=GetAllClaims("XN");
var allinv=GetAllClaims("XI");

var numcl =list_count(allcl);
var numnov=list_count(allnov);
var numinv=list_count(allinv);


codeprt();
var plist=new textList();
var pcount=0;


var html="";
if(numcl) {
   pcount++;
   html+="1."+pcount+". ";
   plist.push("1."+pcount);

   html+="Article 84 EPC with regard to "+plural(numcl,"claim")+" "+List_totext(allcl)+"."+BR;
}

if(numnov) {
   pcount++;
   html+="1."+pcount+". ";
   plist.push("1."+pcount);
   html+=stdcls_apply_nov("opnotnov",allnov,"EPC")+BR;
}

if(numinv) { 
  pcount++;
  html+="1."+pcount+". ";
  plist.push("1."+pcount);
  html+=stdcls_apply_inv("opnotinv",allinv,"EPC")+BR;
}

html+="The applicant's attention is drawn to the arguments raised during the written procedure ";
html+="concerning "+plural(plist.length(),"point")+" "+plist.getText()+"."+BR2;

html+=stdcls_apply_misc("opwarnings","","EPC")+BR;

var header="Summons to oral proceedings."+BR2;

header+="The applicant is summoned to attend the oral proceedings on the ";
header+=MOD_COP.opdate+" at "+MOD_COP.optime+", on behalf of his request for an opportunity to be heard";
header+=" following the requirements of Article 113(1) EPC. ";
header+="The "+plural(pcount,"point")+" to be discussed "+plural(pcount,"is")+" the following :"+BR2;

return header+html+epc_comm("text");
}

// EPC 2K
function do_minutes() {
  var html="";

  html+="The Chairman, Mr. "+MOD_COP.chairman+", opened the Oral Proceedings at "+MOD_COP.optime+"."+BR2;
  html+="Nobody had appeared for the applicant, as the representative, Mr. "+MOD_COP.oprep+", already ";
  html+="anticipated in the fax/letter dated BB.BB.BBBB. The Chairman confirmed that the applicant ";
  html+="had been duly summoned on CC.CC.CCCC."+BR2;

  html+="The Chairman called the porter to enquire whether the representative was there. ";
  html+="This was not the case."+BR2;

  html+="At 10:08 the Chairman interrupted the Oral Proceedings."+BR2;

  html+="At 10:30 the Chairman resumed the Oral Proceedings and called the porter to enquire whether ";
  html+="the representative was there. This was still not the case. The Examining Division checked ";
  html+="in DINO for any late submission. This was not the case, either."+BR2;
  
  html+="The Examining Division deliberated on the case and at 10:35 the Examining Division reached ";
  html+="the decision about the current set of claims. The Chairman announced the decision: \"";
  html+="application number "+MOD_COP.opapp+" is refused by virtue of Article 97(2) EPC, because ";
  html+="the subject-matter of claims ..... does not involve an inventive step in the sense ";
  html+="of Article 56 EPC\"."+BR2;

  html+="At 10:36 the Chairman closed the Oral Proceedings.";

  return html;
}


function show_minutes() {
  var html="<h3>Minutes of oral proceedings</h3>";
  
  html+="<TABLE><TR><TH align=left>";
  html+="<fieldset>";
  html+="<legend>Application</legend><input type=text size=12 value='"+MOD_COP.opapp+"' onChange='MOD_COP.onchangeopapp(this.value);'>";
  html+="</fieldset></TH><TH align=left><fieldset>";
  html+="<legend>Chairman</legend> <input type=text size=24 value='"+MOD_COP.chairman+"' onChange='MOD_COP.onchangemchair(this.value);'>";
  html+="</fieldset></TH><TH align=left><fieldset>";
  html+="<legend>Representative</legend> <input type=text size=24 value='"+MOD_COP.oprep+"' onChange='MOD_COP.onchangemrep(this.value);'>";
  html+="</fieldset></TH><TH align=left><fieldset>";
  html+="<legend>Time</legend><input type=text value='"+MOD_COP.optime+"' size=6 onChange='MOD_COP.onchangemtime(this.value);'>";
  html+="</fieldset>";
  html+="</TH></TR>";
  
  html+="<TR><TD colspan=4>"+comm_area(do_minutes(MOD_COP.chairman,MOD_COP.oprep,MOD_COP.optime))+"</TD></TR>";
  html+="</TABLE>"; 
  MOD_COP.opid=comm_area_last_id();
  return html;
}

function show_prop() {  
  var html="<h3>Summons to oral proceedings</h3>";  
  html+="<TABLE><TR><TD>Date <input type=text value='"+MOD_COP.opdate+"' TABINDEX='1' onChange='MOD_COP.onchangepdate(this.value);'> ";
  html+="Time <input type=text value='"+MOD_COP.optime+"' TABINDEX='2' name='optime' onChange='MOD_COP.onchangeptime(this.value);'> ";
  if(!MOD_COP.runningop()) {
    html+=html_img(img_scheduleop,"","onclick='MOD_COP.onscheduleop()' valign=center");
  }
  html+="</TD></TR>";
  
  html+="<TR><TD>"+comm_area(do_prop(MOD_COP.opdate,MOD_COP.optime))+"</TD></TR>";
  html+="</TABLE>"; 
  MOD_COP.opid=comm_area_last_id();  
  return html;
}


MOD_COP.objtab=[];
MOD_COP.objtab["Summons"]={callback:show_prop};
MOD_COP.objtab["Minutes"]={callback:show_minutes};

function show_op() {  
  MOD_COP.recoverop();  
  ClaimToolCommSection("Oral Proceedings",
		       html_tabs_obj("opview",MOD_COP.objtab));
}
